package com.zc.manager.network.domain;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.annotation.Excel;

import java.util.Date;

/**
 * 证书实体类
 *
 * @author zhaoxianglong
 * @date 2022-11-7
 */
public class IotCertificateInfo {

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @Excel(name = "证书内容")
    private String configuration;

    @Excel(name = "证书类型")
    private String certificateType;

    @Excel(name = "名称")
    private String certificateName;

    @Excel(name = "描述")
    private String description;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @Excel(name = "创建时间", dateFormat = "yyyy-MM-dd HH:mm:ss", type = Excel.Type.EXPORT)
    private Date createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @Excel(name = "注册时间", dateFormat = "yyyy-MM-dd HH:mm:ss", type = Excel.Type.EXPORT)
    private Date updateTime;

    public static class CertificateConfig {

        // 密钥库
        private String keystoreBase64;

        // 信任库
        private String trustKeyStoreBase64;

        // 密钥库密码
        private String keystorePwd;

        // 信任库密码
        private String trustKeyStorePwd;

        public String getKeystoreBase64() {
            return keystoreBase64;
        }

        public void setKeystoreBase64(String keystoreBase64) {
            this.keystoreBase64 = keystoreBase64;
        }

        public String getTrustKeyStoreBase64() {
            return trustKeyStoreBase64;
        }

        public void setTrustKeyStoreBase64(String trustKeyStoreBase64) {
            this.trustKeyStoreBase64 = trustKeyStoreBase64;
        }

        public String getKeystorePwd() {
            return keystorePwd;
        }

        public void setKeystorePwd(String keystorePwd) {
            this.keystorePwd = keystorePwd;
        }

        public String getTrustKeyStorePwd() {
            return trustKeyStorePwd;
        }

        public void setTrustKeyStorePwd(String trustKeyStorePwd) {
            this.trustKeyStorePwd = trustKeyStorePwd;
        }
    }

    public CertificateConfig getCertificateConfig() {

        CertificateConfig certificateConfig = new CertificateConfig();

        JSONObject jsonObject = JSONObject.parseObject(configuration);

        certificateConfig.setKeystoreBase64(jsonObject.getString("keystoreBase64"));
        certificateConfig.setKeystorePwd(jsonObject.getString("keystorePwd"));
        certificateConfig.setTrustKeyStoreBase64(jsonObject.getString("trustKeyStoreBase64"));
        certificateConfig.setTrustKeyStorePwd(jsonObject.getString("trustKeyStorePwd"));

        return certificateConfig;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getConfiguration() {
        return configuration;
    }

    public void setConfiguration(String configuration) {
        this.configuration = configuration;
    }

    public String getCertificateType() {
        return certificateType;
    }

    public void setCertificateType(String certificateType) {
        this.certificateType = certificateType;
    }

    public String getCertificateName() {
        return certificateName;
    }

    public void setCertificateName(String certificateName) {
        this.certificateName = certificateName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
